package com.engr.lyx.blog.biz.controller;

import com.engr.lyx.blog.biz.service.CommentService;
import com.engr.lyx.blog.client.req.CommentReq;
import com.engr.lyx.common.annotation.FreeAccess;
import com.engr.lyx.common.base.ResultBody;
import com.engr.lyx.common.utils.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: blog
 * @description: 评论模块
 * @author: lyx
 * @create: 2019-06-23
 **/
@Api(tags = "评论模块")
@RestController
@RequestMapping(value = "/api/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @PostMapping("/add")
    @ApiOperation(value = "评论-保存", notes = "评论-保存")
    public ResultBody saveArticleComment(@RequestBody CommentReq req) {

        return ResultUtils.success(commentService.saveComment(req));
    }

    @GetMapping("/detail")
    @FreeAccess
    @ApiOperation(value = "查看文章所有评论", notes = "查看文章所有评论")
    public ResultBody getCommentByArticle(@RequestParam String articleId) {

        return ResultUtils.success(commentService.queryTreeByArticleId(articleId));
    }

}
